package it.polimi.registration.business.security.entity;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
public class BadWeather extends Notification implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Calendar proposition;

	private boolean answer;
	private boolean answered;
	
	public BadWeather() {
		this.answered = false;		
	}
	
	public BadWeather(Event event, User owner, Calendar proposition) {
		super(event, owner);
		this.proposition = proposition;
		this.answered = false;	
	}
	
	public Calendar getProposition() {
		return proposition;
	}
	
	public int getDay() {
		return proposition.get(Calendar.DAY_OF_MONTH);
	}
	
	public int getMonth() {
		return proposition.get(Calendar.MONTH) + 1;
	}
	
	public int getYear() {
		return proposition.get(Calendar.YEAR);
	}
	
	public String getPropositionString() {
		return getDay() + "/" +  getMonth() + "/" +  getYear();
	}
	
	private void setAnswer(boolean answer) {
		this.answer = answer;
		this.answered = true;
	}
	
	public boolean isAnswered() {
		return answered;
	}
	
	public boolean getAnswer() {
		return isAnswered() ? answer : false;
	}
	
	public void accept() {
		this.setAnswer(true);
		super.getEvent().setDate(proposition);
	}
	
	public void decline() {
		this.setAnswer(false);
	}
}
